
#include <BFont>
#include <BWidget>
#include "member_BLineEdit.h"

using namespace BWE;

member_BLineEdit::member_BLineEdit(BLineEdit* edit)
{
	boss = edit;
	changed = false;
	pressed = false;
	align = Align_Left | Align_VCenter;
	hoverIndex = 0;
	inputIndex = 0;
	inputCount = 0;
	inputShown = false;
	dirty = true;
}
member_BLineEdit::~member_BLineEdit()
{

}

void member_BLineEdit::freshRects()
{
	const BFont* font = boss->font();
	if (!font)
		return;

	BRect clientRect = boss->clientRect();

	BSize textSize = font->textSize(text);
	textRect = clientRect.align(align, textSize);

	int count = text.count();
	rects.resize(count + 1);

	int tx = textRect.x();
	int ty = textRect.y();
	int th = textRect.height();
	for (auto cit = text.begin(); cit != text.end(); cit++)
	{
		int tw = font->codeWidth(cit.value());
		rects[cit.count()].set(tx, ty, tw, th);
		tx += tw;
	}
	rects.last().set(tx, ty, th, th);

	if (inputIndex < 0)
		inputIndex = 0;
	if (inputIndex > count)
		inputIndex = count;
	if (inputIndex + inputCount >= count)
	{
		inputCount = count - inputIndex;
	}
}
